﻿using System.Collections.Generic;
using UnityEngine;
/*实现镜头选中的效果，以及按下f键镜头靠近的效果*/
public class Select : MonoBehaviour
{
    //公开镜头偏移量
    public Vector3 offset;
    public Vector3 fOffset;
    private Transform target;
    public Transform aim;
    public float speed = 3;
    private void Start()
    {
        offset = new Vector3(0, 0, -10);
        fOffset = new Vector3(0,0,-3);
        target = Camera.main.transform;
    }
    private void OnMouseDown()
    {
        aim.position = transform.position + offset;
        aim.rotation = transform.rotation;
        target = aim;
    }
   private void Update()
   {
       Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation,target.rotation,Time.deltaTime*speed);
       Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position,target.position,Time.deltaTime*speed);
       if (Input.GetKeyDown(KeyCode.F))
       {
           aim.position = transform.position + fOffset;
           aim.rotation = transform.rotation;
           target = aim;
       }
   }
}
